<?php
session_start();
require_once("../db_connect.php");
$thread_contribute_name = array();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet"  href="./../../css/css.css" type="text/css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.0/jquery.min.js"></script>
<script type="text/javascript" src="../../js/jquery.corner.js"></script>
<script type="text/javascript">
$(document).ready(
		function() {
			$('.box').corner();
			$('.box2').corner();
			$('.box3').corner();
			$('.box4').corner();
	});
//未入力項目をチェックする
function chValie() {
// 入力必須項目（「,」で区切って追加可能）
ess = new Array("volunteer_Name","sub_category_id","Location","Activity_Date_year","application_number");
for(i=0; i<ess.length; i++) {
 txt = document.volForm.elements[ess[i]].value;
 if(txt == "") {
   alert("未入力の項目があります");
   return false;
 }
}
return true;
}
</script>
<title>Insert title here</title>
</head>
    <body>
	<div id="container">
		<div id="header" class="box4">
			<div id="header_box" >
				<div id="title">
				</div>
				<div id="search_box">
					<a href="#" id="volunteer">ボランティア</a>｜<a href="#" id="thread">掲示板</a>
					<form method="post" action="../search_function/search_display_free.php?target=volunteer" id="target">
						<input type="text"  name="search_word"><br />
						<input type="submit" value="検索する" id="search_button">
					</form>
				</div>
			</div>
		</div>
		<div id="rightnavi" class="box">
		<?php if(empty($_SESSION["user_name"])&&empty($_SESSION["user_id"])){?>
			<h3>ログインフォーム</h3>
			<form method="post" action="./user_function/UserLogin.php">
				ID：　　<input type="text" name="id" size="10"><br />
				PASS：<input type="text" name="pass" size="10"><br />
				<input style="margin:10px 0 0 39px;" type="image" src="../img/login.png" alt="送信ボタン" name="submit" align="middle">
			</form>
			<a  href="./PHP/User_create.php"><img style="margin:-20px 0 0 39px;" src="../img/newuser.png" border="0"></a>
		<?php }else{?>
				<img src="../../img/kaiinlogo.png" id="kaiinlogo" />
				<p>ようこそ<?php echo $_SESSION['nick_name']?>さん！</p>
				<p><a href="../user_function/user_infomation.php">会員情報表示</a></p>
				<p><a href="../user_function/user_update.php">会員情報変更</a></p>
				<p><a href="../user_function/user_display_application.php">申請中ボランティア</a></p>
				<p><a href="../user_function/user_display_volunteer.php">提供中ボランティア</a></p>
				<p><a href="../volunteer_function/volunteer_information_insert.php">ボランティア作成</a></p>
				<p><a href="logout.php">ログアウト</a></p>
				<br />
		<?php }?>
		<img src="../../img/keizilogo.png" id="keizilogo" />
<ul class="menu_margin">
<div id="thread_title_look">
<?php

	//スレッド項目取得
	$sql = "SELECT t.thread_id,count(thread_name) as thread_count,t.thread_name,max(r.response_date) as response_date,t.thread_id FROM thread AS t LEFT OUTER JOIN response AS r ON t.thread_id = r.thread_id group by t.thread_name order by response_date desc limit 0,5";
	$sth = $db->query($sql);
	if (DB::isError($sth)) {
	  exit($sth->getMessage());
	}

	//スレッド表示
	while ($data = $sth->fetchRow(DB_FETCHMODE_ASSOC)) {
	  echo "<li><a href='../response.php?thread_id=".$data['thread_id']."'>";
	  echo mb_strlen($data['thread_name'])>=9?mb_substr($data['thread_name'],0,9)."...":$data['thread_name'];
	  echo "</a></li>";
	}
?>
				</ul>
		<div id="more"><a href="../../PHP/thread.php" >もっと見る...</a></div>
	</div>
<div id="main"  class="box3">
<h1 align="center">ボランティア情報変更</h1>
<table id="table-06">
<form action="VolunteerInformationUpdate.php"  method="POST" name="volForm" onSubmit="return chValie()" >
<?php
	$user_id = $_SESSION['user_id'];
	$volunteer_information_id  = htmlspecialchars($_GET['volunteer_information_id'],ENT_QUOTES,"UTF-8");

	$sql = "SELECT user_id,volunteer_Name,content,sub_category_id,age,Target_Gender,work_time,Location,access,Conditions,Activity_Date,End_time,
				   application_number,treatment_id,other
			FROM volunteer_information
			WHERE volunteer_information_id = ?";

	$data = array($volunteer_information_id);

	$res =& $db->query($sql, $data);	//SQLを実行して、結果を $res に代入
	if (PEAR::isError($res)) {			//SQLの実行に失敗すればここでエラー文を出力
		die($res->getMessage());
	}

	if ($row =& $res->fetchRow(DB_FETCHMODE_ASSOC)) {
?>
<input type="hidden" name="voluntter_information_id" value="<?php echo $volunteer_information_id?>" />
<tr>
<th>ボランティア名</th><td><input type="text" name="volunteer_Name" value="<?php echo $row['volunteer_Name']?>" /></td></tr>
<tr>
<th>活動内容</th><td><textarea name="content" rows="5" cows="40"  ><?php echo $row['content']?></textarea></td></tr>
<tr>
<th>カテゴリ</th><td><select name="sub_category_id" >
<?php
	$sql = "SELECT sub_category_id,sub_category_name
			FROM sub_category";

	$sth = $db->query($sql);
	if (DB::isError($sth)) {
	  exit($sth->getMessage());
	}

	//カテゴリ表示
	while ($data = $sth->fetchRow(DB_FETCHMODE_ASSOC)) {
		echo "<option value='".$data['sub_category_id']."' >".$data['sub_category_name']."</option>";
	}
?>
</select></td></tr>
<tr>
<th>対象年齢</th><td><input type="text" name="age" value="<?php echo $row['age']?>" /></td></tr>
<tr>
<th>対象性別</th><td>
<select name="Target_Gender">
<option value="<?php echo $row['Target_Gender'];?>" ><?php echo $row['Target_Gender'];?></option>
<?php if($row['Target_Gender']!="不問"){?>
<option value="不問">不問</option>
<?php }
	if($row['Target_Gender']!="男"){?>
<option value="男">男</option>
<?php }
	if($row['Target_Gender']!="女"){?>
<option value="女">女</option>
<?php } ?>
</select></td></tr>
<tr>
<th>実働時間</th><td><input type="text" name="work_time" value="<?php echo $row['work_time']?>" /></td></tr>

<?php
	$Activity_Date_array = explode("-",$row['Activity_Date']);
	$End_time_array = explode("-",$row['End_time']);
?>
<tr>
<th>活動開始日</th><td><select name="Activity_Date_year">
<?php
$now_y = date("Y");
echo "<option value='".$Activity_Date_array[0]."'>".$Activity_Date_array[0]."</option>";
for($i = $now_y; $i<= $now_y+5; $i++):?>
<option value="<?php echo $i;?>"><?php echo $i;?></option>
<?php endfor;?>
</select>年
<select name="Activity_Date_month">
<?php
echo "<option value='".$Activity_Date_array[1]."'>".$Activity_Date_array[1]."</option>";
for($i = 1; $i<=12; $i++):?>
<option value="<?php echo $i;?>"><?php echo $i;?></option>
<?php endfor;?>
</select>月
<select name="Activity_Date_day">
<?php
echo "<option value='".$Activity_Date_array[2]."'>".$Activity_Date_array[2]."</option>";
for($i = 1; $i<=31; $i++):?>
<option value="<?php echo $i;?>"><?php echo $i;?></option>
<?php endfor;?>
</select>日</td></tr>

<tr>
<th>活動終了日</th><td><select name="End_time_year">
<?php
$now = date("Y");
echo "<option value='".$End_time_array[0]."'>".$End_time_array[0]."</option>";
for($i = $now; $i<= $now+5; $i++):?>
<option value="<?php echo $i;?>"><?php echo $i;?></option>
<?php endfor;?>
</select>年
<select name="End_time_month">
<?php
echo "<option value='".$End_time_array[1]."'>".$End_time_array[1]."</option>";
for($i = 1; $i<=12; $i++):?>
<option value="<?php echo $i;?>"><?php echo $i;?></option>
<?php endfor;?>
</select>月
<select name="End_time_day">
<?php
echo "<option value='".$End_time_array[2]."'>".$End_time_array[2]."</option>";
for($i = 1; $i<=31; $i++):?>
<option value="<?php echo $i;?>"><?php echo $i;?></option>
<?php endfor;?>
</select>日</td></tr>
<tr>
<th>活動場所</th><td><input type="text" name="Location" value="<?php echo $row['Location']?>" /></td></tr>
<tr>
<th>アクセス方法</th><td><input type="text" name="access" value="<?php echo $row['access']?>" /></td></tr>
<tr>
<th>条件</th><td><input type="text" name="Conditions" value="<?php echo $row['Conditions']?>" /></td></tr>
<tr>
<th>応募人数</th><td><input type="text" name="application_number" value="<?php echo $row['application_number']?>" /></td></tr>
<tr>
<th>待遇</th><td>
<?php
	$sql = "SELECT treatment_id,treatment_name
			FROM treatment";

	$sth = $db->query($sql);
	if (DB::isError($sth)) {
	  exit($sth->getMessage());
	}

	//カテゴリ表示
	while ($data = $sth->fetchRow(DB_FETCHMODE_ASSOC)) {
		echo "<input type='checkbox' name='treatment_id' value='".$data['treatment_id']."' />".$data['treatment_name'];
	}
?>
</td></tr>
<tr>
<th>その他</th><td><textarea name="other" rows="5" cows="40" ><?php echo $row['other']?></textarea></td></tr>
<?php }?>
</table>
<input type="submit" value="登録" />
</form>
</div>
<div id="space"></div>
</div>
    </body>
</html>
